﻿app.directive('myDirective', function () {
    return {
        require: 'ngModel',
        scope: { CheckDuplicateCode: '&' },
        link: function (scope, element, attr, mCtrl) {
            function myValidation(value) {
                if (CheckDuplicateCode(value)) {
                    mCtrl.$setValidity('CheckDuplicateCode', true);
                } else {
                    mCtrl.$setValidity('CheckDuplicateCode', false);
                }
                return value;
            }
            mCtrl.$parsers.push(myValidation);
        }
    };
});